package org.marsdonne.audits.messenger;

import org.marsdonne.audits.Exception;
import org.marsdonne.audits.*;
import org.marsdonne.audits.repos.*;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class LogsRecorder {

    @Resource
    private ChangeRepos changeRepos;

    @Resource
    private ExceptionRepos exceptionRepos;

    @Resource
    private AuthRepos authRepos;

    @Resource
    private NoteRepos noteRepos;

    @Resource
    private OperationRepos operationRepos;

    @JmsListener(
            containerFactory = "auditsJmsListenerFactory", concurrency = "1-5",
            destination = "${audits.artemis.channel.changed:channels.audits.changed}")
    public void changed(Changed changed) {
        changeRepos.save(new Change(changed));
    }

    @JmsListener(
            containerFactory = "auditsJmsListenerFactory", concurrency = "1-5",
            destination = "${audits.artemis.channel.caught:channels.audits.caught}")
    public void capture(Caught caught) {
        exceptionRepos.save(new Exception(caught));
    }

    @JmsListener(
            containerFactory = "auditsJmsListenerFactory", concurrency = "1-5",
            destination = "${audits.artemis.channel.identified:channels.audits.identified}")
    public void identity(Identified identified) {
        authRepos.save(new Auth(identified));
    }

    @JmsListener(
            containerFactory = "auditsJmsListenerFactory", concurrency = "1-5",
            destination = "${audits.artemis.channel.noted:channels.audits.noted}")
    public void record(Noted noted) {
        noteRepos.save(new Note(noted));
    }

    @JmsListener(
            containerFactory = "auditsJmsListenerFactory", concurrency = "1-5",
            destination = "${audits.artemis.channel.operated:channels.audits.operated}")
    public void used(Operated operated) {
        operationRepos.save(new Operation(operated));
    }
}
